﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FrameDisplayServer.UI.Settings
{
    public partial class PickScreenForm : Form
    {
        private string initialScreenName;

        public PickScreenForm()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            int indexToSelect = 0;

            Screen[] screens = Screen.AllScreens;
            int co = 0;
            foreach (Screen screen in screens)
            {
                this.comboBoxScreen.Items.Add(new ScreenItem(screen));

                if (screen.DeviceName == this.initialScreenName)
                {
                    indexToSelect = co;
                }

                co++;
            }

            this.comboBoxScreen.SelectedIndex = indexToSelect;
        }

        public string ScreenName
        {
            get 
            {
                ScreenItem item = (ScreenItem)this.comboBoxScreen.SelectedItem;
                if (item != null)
                {
                    return item.DeviceName;
                }

                return null;
            }

            set { this.initialScreenName = value; }
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private class ScreenItem
        {
            private Screen screen;

            public ScreenItem(Screen screen)
            {
                this.screen = screen;
            }

            public string DeviceName { get { return this.screen.DeviceName; } }

            public override string ToString()
            {
                return this.DeviceName;
            }
        }

       
    }
}
